//
//  AnimationViewController.swift
//  UI
//
//  Created by admin on 14/9/18.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit

let reuseIdentifier = "Cell"
var animation_view = ["淡入淡出","视图交换","视图翻转"]
var image_urls_view = ["1410879484_Light-128","1410879482_MagicStar-128","1410879479_Statistics-128"]
var segue_id_view = ["fadeInOut","exchange","Flip"]

var animation_cat = ["一般CA调用","翻页过渡","视图反弹","图像动画","视图映射"]
var image_urls_cat = ["1410879477_BookShell-128","1410879475_Monitor-128","1410879473_Calendar-128","1410879471_Tag-128","1410879470_Clock-128"]
var segue_id_cat = ["one","two","three","four","five"]

var animation_customer = ["Cube","Door","Drop", "Slip"]
var image_urls_customer = ["1410879460_Television-128","1410879470_Clock-128","1410879460_Television-128", "1410879447_NumberOne-128"]
var segue_id_customer = ["Cube","Door","Drop","Slip"]


class AnimationViewController: UICollectionViewController {
    let transitionManager = TransitionManager()
    var animations = [animation_view, animation_cat, animation_customer]
    var image_urls = [image_urls_view, image_urls_cat, image_urls_customer]
    var segues = [segue_id_view, segue_id_cat, segue_id_customer]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "动画"

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Register cell classes
        self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

        // Do any additional setup after loading the view.
        
       
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
        println("fadeInOut")
        let toVC = segue.destinationViewController as UIViewController
        toVC.transitioningDelegate = self.transitionManager
        //fadeInOut
    }


    // MARK: UICollectionViewDataSource

    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        //#warning Incomplete method implementation -- Return the number of sections
        return self.animations.count
    }


    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        //#warning Incomplete method implementation -- Return the number of items in the section
        return self.animations[section].count
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
        cell.backgroundColor = UIColor.whiteColor()
        // Configure the cell
        var label = UILabel(frame: CGRectMake(0, 60, 79, 20))
        label.font = UIFont(name: "Helvetica", size: 11.0)
        label.textAlignment = NSTextAlignment.Center
        label.text = self.animations[indexPath.section][indexPath.row]
    
        var image_url = self.image_urls[indexPath.section][indexPath.row]
        var imageView = UIImageView(image: UIImage(named: image_url))
        imageView.frame = CGRectMake(20, 20, 40, 40)
        
        cell.contentView.addSubview(label)
        cell.contentView.addSubview(imageView)
        
       // cell.selectedBackgroundView.backgroundColor = UIColor.grayColor()

        return cell
    }

    // MARK: UICollectionViewDelegate

    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
        var segue = self.segues[indexPath.section][indexPath.row]
        performSegueWithIdentifier(segue, sender: self)
    
    }
    override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath){
    
    }
    
    
    
    // Uncomment this method to specify if the specified item should be highlighted during tracking
    override func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
    }


    
    // Uncomment this method to specify if the specified item should be selected
    override func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
    }


    /*
    // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
    func collectionView(collectionView: UICollectionView!, shouldShowMenuForItemAtIndexPath indexPath: NSIndexPath!) -> Bool {
        return false
    }

    func collectionView(collectionView: UICollectionView!, canPerformAction action: String!, forItemAtIndexPath indexPath: NSIndexPath!, withSender sender: AnyObject!) -> Bool {
        return false
    }

    func collectionView(collectionView: UICollectionView!, performAction action: String!, forItemAtIndexPath indexPath: NSIndexPath!, withSender sender: AnyObject!) {
    
    }
    */

}
